package com.yanzhen.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yanzhen.dao.RosterMapper;
import com.yanzhen.model.Roster;
import com.yanzhen.service.IRosterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author kappy
 * @since 2021-04-29
 */
@Service
public class RosterServiceImpl extends ServiceImpl<RosterMapper, Roster> implements IRosterService {

    @Autowired
    private RosterMapper rosterDao;

    @Override
    public PageInfo<Roster> findRosterAll(int page, int pageSize, String wdayday) {
        PageHelper.startPage(page,pageSize);
        //查询的结果集
        List<Roster> list = rosterDao.queryRosterAll(wdayday);
        PageInfo<Roster> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public IPage<Roster> findListByPage(Integer page, Integer pageCount){
        IPage<Roster> wherePage = new Page<>(page, pageCount);
        Roster where = new Roster();

        return   baseMapper.selectPage(wherePage, Wrappers.query(where));
    }

    @Override
    public int add(Roster roster){
        return baseMapper.insert(roster);
    }

    @Override
    public int delete(Long id){
        return baseMapper.deleteById(id);
    }

    @Override
    public int updateData(Roster roster){
        return baseMapper.updateById(roster);
    }

    @Override
    public Roster findById(Long id){
        return  baseMapper.selectById(id);
    }
}
